package com.ruoyi.course.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.course.domain.CourseVideos;
import com.ruoyi.course.service.ICourseVideosService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程视频关联Controller
 *
 * @author ruoyi
 * @date 2025-08-13
 */
@RestController
@RequestMapping("/course/videos")
public class CourseVideosController extends BaseController
{
    @Autowired
    private ICourseVideosService courseVideosService;

    // 其他方法保持不变
    @PreAuthorize("@ss.hasPermi('course:videos:list')")
    @GetMapping("/list")
    public TableDataInfo list(CourseVideos courseVideos)
    {
        startPage();
        List<CourseVideos> list = courseVideosService.selectCourseVideosList(courseVideos);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('course:videos:export')")
    @Log(title = "课程视频关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseVideos courseVideos)
    {
        List<CourseVideos> list = courseVideosService.selectCourseVideosList(courseVideos);
        ExcelUtil<CourseVideos> util = new ExcelUtil<CourseVideos>(CourseVideos.class);
        util.exportExcel(response, list, "课程视频关联数据");
    }

    @PreAuthorize("@ss.hasPermi('course:videos:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(courseVideosService.selectCourseVideosById(id));
    }

    @PreAuthorize("@ss.hasPermi('course:videos:add')")
    @Log(title = "课程视频关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseVideos courseVideos)
    {
        return toAjax(courseVideosService.insertCourseVideos(courseVideos));
    }

    @PreAuthorize("@ss.hasPermi('course:videos:edit')")
    @Log(title = "课程视频关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseVideos courseVideos)
    {
        return toAjax(courseVideosService.updateCourseVideos(courseVideos));
    }

    @PreAuthorize("@ss.hasPermi('course:videos:remove')")
    @Log(title = "课程视频关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(courseVideosService.deleteCourseVideosByIds(ids));
    }
}